<!--
//	****************************************************************************
//	JSFighter inspired by MUGEN
//	Copyright (c) 2011 Unni Vemanchery Mana
//	****************************************************************************
//	This program is free software; you can redistribute it and/or modify it
//	under the terms of the GNU Lesser General Public License as published by the
//	Free Software Foundation; either version 3 of the License, or (at your
//	option) any later version.
//	This program is distributed in the hope that it will be useful, but x
//	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
//	more details.
//	You should have received a copy of the GNU Lesser General Public License along
//	with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
//	****************************************************************************
-->

 <html>
    <head>
        <!--<script src="jquery-14a.js"></script>-->
		<script src="jquery.min.js"></script>
        <script src="jquery.gamequery-0.5.1.js"></script>
        <script>

            var PLAYGROUND_WIDTH  = 700;
            var PLAYGROUND_HEIGHT = 350;   
            var currentAnimation  = null;
            var defaultAnimation  = null;
            var aboboCurrentAnimation = null;
            var aboboDefaultAnimation = null; 
            var res ;
            var xPos = 0; // -150;
            var kdown = false;
            var kup   = false;
            //var imagePath = "./Archive1/";
			var imagePath = "";
            //var aboboPath = "./abobo/";
			var aboboPath = ""; 
            //var palyGroundPath = "./stage/";
            var palyGroundPath = "";
            var gameOver  = false;
            var aboboXPos = 500; //50;
            var aboboFallXPos = 400;
            var anyKeyPressed = false;
            var idleTimer = 0;  
             
            // this variable keeps track of abobo's attack including
            // all its possible movements.
   
            var aboboAttackCount = 0;
            var userAttackCount  = 0; 

            var aboboHealthCount = 0;
            var ABOBOMINHEALTH = 5;    

            var DISTANCE = 165;

            var isCollided = false;

            var xdelta = 10;
            
			var start = true;

			var FRONT = true;

            var PLAYERFRONT = true;

            var aboboTimer = null;

			var level = 1;
			
			var deltaCount = 2;

            var playerLifeCounter = 0;
			
            $(function(){

                var playGroundAnimation = new Array(6); 
                var aboboAnimation  = new Array(10);
                var playerAnimation = new Array(29);
				var aboboLife  = [];
				var playerLife = [];
				var moves = new Array(4);

                var currMove = "PUNCH"; 
				moves[0]  = "IDLE";
				moves[1]  = "PUNCH";
                moves[2]  = "KICK";   
                moves[3]  = "BLOCK";    

                aboboAnimation["aboboRightPunch"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_punch_131x170x4.png",  numberOfFrame: 4, delta: 131, rate: 150,
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_CALLBACK});
           
                aboboAnimation["aboboWalkForward"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_walk_forward_94x126x6.png",  numberOfFrame: 6, delta: 94, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL});

		        aboboAnimation["aboboFallBack"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_walk_backward_94x126x6.png",  numberOfFrame: 3, delta: 94, rate: 150, type: $.gameQuery.ANIMATION_HORIZONTAL});
	                
     		    aboboAnimation["aboboHit"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_hit_108x120x3.png",  numberOfFrame: 3, delta: 108, rate: 1500, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_CALLBACK});
                 
     		    aboboAnimation["aboboKick"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_kick_137x130x2.png",  numberOfFrame: 2, delta: 137, rate: 500, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_CALLBACK});

           		aboboAnimation["aboboIdle"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_idle_100x121x3.png",  numberOfFrame: 3, delta: 100, rate: 500, type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_CALLBACK});
 
           		aboboAnimation["aboboBlock"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobo_block_81x130x1.png",  rate: 900, 
				type:  $.gameQuery.ANIMATION_CALLBACK});

          		aboboAnimation["aboboWin"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobowin.png",  numberOfFrame: 4, delta: 157, rate: 250, type:  $.gameQuery.ANIMATION_HORIZONTAL});

                aboboLife["life"] = new $.gameQuery.Animation({imageURL: aboboPath + "abobolife.png", rate: 950, type: $.gameQuery.ANIMATION_CALLBACK});

                playerLife["life"] = new $.gameQuery.Animation({imageURL: aboboPath + "playerlife.png", rate: 950, type: $.gameQuery.ANIMATION_CALLBACK});
  
				playerAnimation["ryuWalkAgo"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_andando_para_atras.png",  numberOfFrame: 7, delta: 292, rate: 90,type: $.gameQuery.ANIMATION_HORIZONTAL});      

                playerAnimation["ryuBeatLeft"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_porrada_para_esquerda.png",  numberOfFrame: 4, delta: 290, rate: 100, type: $.gameQuery.ANIMATION_HORIZONTAL |$.gameQuery.ANIMATION_CALLBACK});

                playerAnimation["ryuApanhando1"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_apanhando1.png",  numberOfFrame: 7, delta: 290, rate: 120,   
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});
 
                playerAnimation["ryuApanhando2"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_apanhando2.png",  numberOfFrame: 7, delta: 290, rate: 120,   
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});
 		    	
                playerAnimation["ryuRollForward"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_apanhando3.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});

                playerAnimation["ryuApanhando4"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_apanhando4.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});

                playerAnimation["ryuApanhando5"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_apanhando5.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});

                playerAnimation["ryuDownDefence"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_defesa_para_baixo.png",  numberOfFrame: 6, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL});

                playerAnimation["ryuUnderDefence"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_defesa_por_baixo.png",  numberOfFrame: 5, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL});
 
                playerAnimation["ryuTopEscape"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_escapando_por_cima.png",  numberOfFrame: 5, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL});
 
                playerAnimation["ryuGingando"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_gingando.png",  numberOfFrame: 2, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL});

                playerAnimation["ryugolpesDeKarate"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_golpesDeKarate.png",  numberOfFrame: 7, delta: 290, rate: 90, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});
  
                playerAnimation["ryugolpesRasteiros"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_golpesRasteiros.png",  numberOfFrame: 7, delta: 290, rate: 40, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI |$.gameQuery.ANIMATION_CALLBACK, distance:200});
                  
                playerAnimation["ryugolpesSuperiores"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_golpesSuperiores.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});
   
                playerAnimation["ryuhaduken"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_haduken.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});
                 
                playerAnimation["ryuhelicoptero"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_helicoptero.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});
  
                playerAnimation["ryuoutrosgolpes2"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_outros_golpes2.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});  
                 
                playerAnimation["ryuoutrosgolpes"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_outros_golpes.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});  

                playerAnimation["ryupezadas1"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_pezadas1.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});  

                playerAnimation["ryupezadas2"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_pezadas2.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});  

                playerAnimation["ryuporradaparaesquerda"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_porrada_para_esquerda.png",  numberOfFrame: 4, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL});  
 							 
                playerAnimation["ryurolandoparafrente"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_rolando_para_frente.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL}); 

                playerAnimation["ryusaltoporcimadooponente"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_salto_por_cima_do_oponente.png",  numberOfFrame: 7, delta: 290, rate: 120, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200}); 

                playerAnimation["ryusocos1"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_socos1.png",  numberOfFrame: 7, delta: 290, rate: 90, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200}); 

                playerAnimation["ryusocos2"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_socos2.png",  numberOfFrame: 7, delta: 290, rate: 90, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});     

                playerAnimation["ryusubindo"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_subindo.png",  numberOfFrame: 7, delta: 290, rate: 90, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});     
 
                playerAnimation["ryuwin"] = new $.gameQuery.Animation({imageURL: imagePath+"ryu_win.png",  numberOfFrame: 7, delta: 290, rate: 90, 
                type: $.gameQuery.ANIMATION_HORIZONTAL | $.gameQuery.ANIMATION_MULTI, distance:200});     
 
                playerAnimation["ryufailed"] = new $.gameQuery.Animation({imageURL: aboboPath + "ryufailed.png",  rate: 900, type:  $.gameQuery.ANIMATION_CALLBACK});

                // adding playground sprite image
                playGroundAnimation["foreground"]  = new $.gameQuery.Animation({imageURL: palyGroundPath + "foreground.png", type: $.gameQuery.ANIMATION_VERTICAL});
                playGroundAnimation["ground"] 	   = new $.gameQuery.Animation({imageURL: palyGroundPath + "ground.png"});
                playGroundAnimation["background1"] = new $.gameQuery.Animation({imageURL: palyGroundPath + "background1.png"});
                playGroundAnimation["background2"] = new $.gameQuery.Animation({imageURL: palyGroundPath + "background2.png"});
                playGroundAnimation["background3"] = new $.gameQuery.Animation({imageURL: palyGroundPath + "background3.png"});
 
    
                $("#playground").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH})
                .addGroup("actors", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT})
                //.addGroup("player", {posx: PLAYGROUND_WIDTH/2, posy: PLAYGROUND_HEIGHT/2, width: 100, height: 26})
                .addGroup("player", {posx: 0, posy: 0, width: PLAYGROUND_WIDTH, height: 126})
                .addSprite(	"background3",
								{posx: 90, posy: 0,
								 height: 200, width: 534,
								 animation: playGroundAnimation["background3"]})
					.addSprite(	"background2",
								{posx:30, posy: -50,
								 height: 180, width: 432,
								 animation: playGroundAnimation["background2"]})
					.addSprite(	"background1",
								{posx:50, posy: -150,
								 height: 317, width: 749,
								 animation: playGroundAnimation["background1"]})
					.addSprite(	"ground",
								{posx: -300, posy: 0,
								 height: 200, width: 1493,
								 animation: playGroundAnimation["ground"]}).addGroup("player").end()
					.addSprite(	"foreground",
								{posx:-800, posy: 165,
								 height: 44, width: 2000,
								 animation: playGroundAnimation["foreground"]})
                .addSprite("aboboRightPunch",{animation: aboboAnimation["aboboRightPunch"],
                posx: aboboXPos, posy: 0, width: 131, height: 170, callback: aboboAttackAnimation})
                .addSprite("aboboFallBack", {animation: aboboAnimation["aboboFallBack"],
                posx: aboboXPos, posy: 40, width: 91, height: 125, callback: aboboAttackAnimation})
			   .addSprite("aboboWalkForward", {animation: aboboAnimation["aboboFallBack"],
                posx: aboboXPos, posy: 40, width: 91, height: 125, callback: aboboAttackAnimation})
                .addSprite("aboboHit", {animation: aboboAnimation["aboboHit"],
                posx: aboboXPos, posy: 40, width: 108, height: 113, callback: aboboAttackAnimation})
                .addSprite("aboboKick", {animation: aboboAnimation["aboboKick"],
                posx: aboboXPos, posy: 40, width: 137, height: 130, callback: aboboAttackAnimation})
		        .addSprite("aboboIdle", {animation: aboboAnimation["aboboIdle"],
                 posx: aboboXPos, posy: 40, width: 100, height: 121, callback: aboboAttackAnimation})
				.addSprite("aboboBlock", {animation: aboboAnimation["aboboBlock"],
                 posx: aboboXPos, posy: 40, width: 81, height: 130, callback: aboboAttackAnimation})
                 .addSprite("aboboWin", {animation: aboboAnimation["aboboWin"],
                 posx: aboboXPos, posy: 0, width: 168, height: 198, callback: aboboAttackAnimation})
 				 .addSprite("0A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 10, width: 168, height: 198})
                 .addSprite("1A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 30, width: 168, height: 198})
                .addSprite("2A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 50, width: 168, height: 198})
				 .addSprite("3A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 70, width: 168, height: 198})
				 .addSprite("4A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 90, width: 168, height: 198})
				 .addSprite("5A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 110, width: 168, height: 198})
				 .addSprite("6A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 130, width: 168, height: 198})
                 .addSprite("7A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 150, width: 168, height: 198})
                 .addSprite("8A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 170, width: 168, height: 198})
				 .addSprite("9A", {animation: aboboLife["life"], 
				 posx: (aboboXPos+170), posy: 190, width: 168, height: 198})

                 .addSprite("0P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 10, width: 168, height: 198})
                 .addSprite("1P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 30, width: 168, height: 198})
				 .addSprite("2P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 50, width: 168, height: 198})
				 .addSprite("3P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 70, width: 168, height: 198})
				 .addSprite("4P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 90, width: 168, height: 198})
			 	 .addSprite("5P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 110, width: 168, height: 198})
				 .addSprite("6P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 130, width: 168, height: 198})
 				 .addSprite("7P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 150, width: 168, height: 198})
 				 .addSprite("8P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 170, width: 168, height: 198})
 				 .addSprite("9P", {animation: playerLife["life"], 
				 posx: (xPos-1), posy: 190, width: 168, height: 198})

                 .addSprite("ryuWalkAgo",{animation: playerAnimation["ryuWalkAgo"],
                 posx: xPos, posy: 0, width: 290, height: 160})
//                .addSprite("ryuBeatLeft",{animation: playerAnimation["ryuBeatLeft"], 
//                 posx: -190, posy: 0, width: 254, height: 160})
 //               .addSprite("ryuApanhando1",{animation: playerAnimation["ryuApanhando1"], 
 //                posx: -50, posy: 0, width: 254, height: 160})
 //               .addSprite("ryuApanhando2",{animation: playerAnimation["ryuApanhando2"], 
 //                posx: -150, posy: 0, width: 254, height: 160})
  //              .addSprite("ryuRollForward",{animation: playerAnimation["ryuRollForward"], 
  //               posx: -200, posy: 0, width: 254, height: 160})
  //              .addSprite("ryuApanhando4",{animation: playerAnimation["ryuApanhando4"], 
  //               posx: -250, posy: 0, width: 254, height: 160})
  //              .addSprite("ryuApanhando5",{animation: playerAnimation["ryuApanhando5"], 
  //               posx: -280, posy: 0, width: 254, height: 160})
  //              .addSprite("ryuDownDefence",{animation: playerAnimation["ryuDownDefence"], 
  //               posx: -280, posy: 0, width: 254, height: 160})
  //              .addSprite("ryugolpesDeKarate",{animation: playerAnimation["ryugolpesDeKarate"], 
  //               posx: -300, posy: 0, width: 254, height: 160});

                  .addSprite("ryuBeatLeft",{animation: playerAnimation["ryuBeatLeft"], 
                   posx: xPos, posy: 0, width: 254, height: 160, callback: animate})
                  .addSprite("ryuApanhando1",{animation: playerAnimation["ryuApanhando1"], 
                   posx: 0, posy: 0, width: 254, height: 160})
                  .addSprite("ryuApanhando2",{animation: playerAnimation["ryuApanhando2"], 
                   posx: 0, posy: 0, width: 254, height: 160})
                  .addSprite("ryuRollForward",{animation: playerAnimation["ryuRollForward"], 
                   posx: 0, posy: 0, width: 254, height: 160})
                  .addSprite("ryuApanhando4",{animation: playerAnimation["ryuApanhando4"], 
                   posx: 0, posy: 0, width: 254, height: 160})
                  .addSprite("ryuApanhando5",{animation: playerAnimation["ryuApanhando5"], 
                   posx: 0, posy: 0, width: 254, height: 160})
                  .addSprite("ryuDownDefence",{animation: playerAnimation["ryuDownDefence"], 
                   posx: 0, posy: 0, width: 254, height: 160})
                  .addSprite("ryugolpesDeKarate",{animation: playerAnimation["ryugolpesDeKarate"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryugolpesRasteiros",{animation: playerAnimation["ryugolpesRasteiros"], 
                   posx: 90, posy: 0, width: 254, height: 160,  callback: animate})
                  .addSprite("ryuhaduken",{animation: playerAnimation["ryuhaduken"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryuhelicoptero",{animation: playerAnimation["ryuhelicoptero"], 
                   posx: 90, posy: 0, width: 254, height: 160})  
                  .addSprite("ryuoutrosgolpes2",{animation: playerAnimation["ryuoutrosgolpes2"], 
                   posx: 90, posy: 0, width: 254, height: 160})  
                  .addSprite("ryuoutrosgolpes",{animation: playerAnimation["ryuoutrosgolpes"], 
                   posx: 90, posy: 0, width: 254, height: 160}) 
                  .addSprite("ryupezadas1",{animation: playerAnimation["ryupezadas1"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryupezadas2",{animation: playerAnimation["ryupezadas2"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryuporradaparaesquerda",{animation: playerAnimation["ryuporradaparaesquerda"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryurolandoparafrente",{animation: playerAnimation["ryurolandoparafrente"], 
                   posx: 90, posy: 0, width: 254, height: 160}) 
                  .addSprite("ryusaltoporcimadooponente",{animation: playerAnimation["ryusaltoporcimadooponente"], 
                   posx: 90, posy: 0, width: 254, height: 160}) 
                  .addSprite("ryusocos1",{animation: playerAnimation["ryusocos1"], 
                   posx: 90, posy: 0, width: 254, height: 160}) 
                  .addSprite("ryusocos2",{animation: playerAnimation["ryusocos2"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryusubindo",{animation: playerAnimation["ryusubindo"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                  .addSprite("ryuwin",{animation: playerAnimation["ryuwin"], 
                   posx: 90, posy: 0, width: 254, height: 160})
                   .addSprite("ryufailed",{animation: playerAnimation["ryufailed"], 
                   posx: 90, posy: 0, width: 254, height: 160});  

                $("#aboboRightPunch").hide();
                $("#aboboWalkForward").hide();
	            $("#aboboFallBack").hide();
                $("#aboboHit").hide(); 
				$("#aboboKick").hide();
				$("#aboboBlock").hide();
                $("#aboboWin").hide();

                $("#ryuBeatLeft").hide();  
                $("#ryuApanhando1").hide();
                $("#ryuApanhando2").hide();  
                $("#ryuRollForward").hide();    
                $("#ryuApanhando4").hide();
                $("#ryuApanhando5").hide();
                $("#ryuDownDefence").hide();
                $("#ryuUnderDefence").hide();
                $("#ryuTopEscape").hide();
                $("#ryuGingando").hide();
                $("#ryugolpesDeKarate").hide();
                $("#ryugolpesRasteiros").hide(); 
                $("#ryuhaduken").hide();
                $("#ryuhelicoptero").hide();  
                $("#ryuoutrosgolpes2").hide();
                $("#ryuoutrosgolpes").hide();
                $("#ryupezadas1").hide();
                $("#ryupezadas2").hide();
                $("#ryuporradaparaesquerda").hide(); 
                $("#ryurolandoparafrente").hide();
                $("#ryusaltoporcimadooponente").hide();
                $("#ryusocos1").hide();
                $("#ryusocos2").hide();
                $("#ryusubindo").hide();
                $("#ryuwin").hide();  
				$("#ryufailed").hide();
 
                defaultAnimation =  $("#ryuWalkAgo");  // this is the default position
                
				aboboDefaultAnimation = $("#aboboIdle");
				aboboDefaultAnimation.show(); 

                startPlayerTimer();

                $.playground().registerCallback(function() {
                      //var collided = $("#ryuWalkAgo").collision("#aboboRightPunch,.group");
                      //var collided = $("#ryuWalkAgo").collision("#aboboRightPunch,.group");  
                      //var collided = $("#ryuWalkAgo").collision(".group,#aboboRightPunch");
                      if(detectCollision()) {
                             setCollided();
                                if( userAttackCount > aboboAttackCount ) { 
                                     userAttackCount = 0;
									 aboboAttackCount = 0; 
									 var sprite = aboboDefaultAnimation;
									 sprite.hide();
									 aboboDefaultAnimation = $("#aboboHit");
							 	     aboboDefaultAnimation.css("left", "" + aboboXPos + "px");
									 aboboDefaultAnimation.show();
								     alert("player won......");
									 log(" player won.....");
							    }else if( userAttackCount <= 0 ) {
			                		 userAttackCount = 0;
								}
                        }
                }, 30);

                function animate() {
				     if(currMove == 'BLOCK'){
                        userAttackCount--;
				    }
	            log("userAttackCount..."+userAttackCount);
              }

		      function gameOverAnimation(){
			   if( gameOver ) return false;
			     setTimeout(function(){
                 defaultAnimation.remove();
				 defaultAnimation = $("#ryufailed");
				 defaultAnimation.css("left", ""+(xPos + 60)+"px");
				 defaultAnimation.css("top", "" + 120 + "px");
				 defaultAnimation.show();
			    }, 2000);
			  }

				var first = true;
                function aboboAttackAnimation() {
				  if( gameOver ) return false;
				  var sprite = null; 
				   if( isCollided ){	   
				    if( first ) {
					    currMove = 'PUNCH';
						first    = false;
						clearTimeout( aboboTimer );
					 }
				      if( currMove == 'PUNCH'){
				      aboboDefaultAnimation.hide();
				      aboboDefaultAnimation = $("#aboboRightPunch");
                      aboboDefaultAnimation.show();
					  aboboDefaultAnimation.css("left", "" + aboboXPos + "px");
					  aboboAttackCount = aboboAttackCount + deltaCount;
			       }
				   if(currMove == 'KICK'){
				        aboboDefaultAnimation.hide();
                        aboboDefaultAnimation = $("#aboboKick");
						aboboDefaultAnimation.show();
						aboboDefaultAnimation.css("left", "" + aboboXPos + "px");
						aboboAttackCount = aboboAttackCount + deltaCount;
                   }
                   if(currMove == 'IDLE'){
     			   } 
				  if(currMove == 'BLOCK'){
				        if( kdown ){
				        aboboDefaultAnimation.hide();
                aboboDefaultAnimation = $("#aboboBlock");
						aboboDefaultAnimation.show();
						aboboDefaultAnimation.css("left", "" + aboboXPos + "px");
						}
                  }
                  aboboTimer = setTimeout(function(){
					 currMove = getMoves(moves);
					}, 3000);
                  }
				  else {
				        first = true;
					    var sprite = aboboDefaultAnimation;
						sprite.hide();
                        aboboDefaultAnimation = $("#aboboWalkForward");
						aboboDefaultAnimation.show();
						if( aboboXPos < 300) {
						   FRONT = false; 
		                }
						else if( aboboXPos >= 500 ) {
                          FRONT = true;   
                        }
                        if( FRONT )  aboboXPos = aboboXPos - 5;
						else aboboXPos = aboboXPos + 5;
						aboboDefaultAnimation.css("left", "" + aboboXPos + "px");     
				  }
                }
                
                function distanceBetweenSprite(a, b) {
                  return Math.abs(a.position().left - b.position().left());    
                }
  
                function startPlayerTimer() {
                   setInterval(function(){
                      updatePlayerTimer();
				   }, 5000);
				}

				function updatePlayerTimer() {
				  if(isCollided){
                  if( aboboAttackCount > userAttackCount ) {
                      $("#" + playerLifeCounter + "P").hide();
					   if(playerLifeCounter >= 9){
					     whoWon();
                         return false;
					  }
                      playerLifeCounter++;
				  }
                 } 
				}

                $( document ).keydown( function(e) {
   		           switch( e.keyCode ) {
                       case 80: // 'p' key pressed, it is a 'punch' move
					          changePlayerAnimation($("#ryugolpesRasteiros"), 0);
                              break; 

                        case 65: // A key pressed
						       changePlayerAnimation($("#ryugolpesRasteiros"), 4);
                               break;   
                     
                        case 83: // S key pressed
				              changePlayerAnimation($("#ryugolpesRasteiros"), 1);
                              break;   

                        case 68: // D key pressed
						      changePlayerAnimation($("#ryugolpesRasteiros"), 2);
                              break;

                       case 70: // F key pressed
					           changePlayerAnimation($("#ryugolpesRasteiros"), 3);
                               break;

                       case 71: // G key pressed
					           changePlayerAnimation($("#ryuBeatLeft"), 0); 
                               break;
                       
                       case 72: // H key pressed
                               break;
    
                       case 90:  // 'Z' key pressed
                               break;   
 
                       case  88: // 'X' key pressed
                              break;

                       case 67: // 'C' key pressed
                            break; 

                        case 39: // right arrow key pressed
                             moveRight();  
                             break;
                          
                        case 37:
                             moveLeft();  
                             break;
                        } 										
                });

                $(document).keyup(function(e) {
                  switch(e.keyCode){

                  case 80:
                          stopCurrentAnimation();   
                          break;  

                  case 65: 
                          stopCurrentAnimation(); 
                          break;      

                  case 83:
                          stopCurrentAnimation();
                          break; 

                  case 68: 
                          stopCurrentAnimation();
                          break;
                  
                  case 70: 
                          stopCurrentAnimation();
                          break;

                  case 71: 
                          stopCurrentAnimation();
                          break;    
                  
                  case 37:
                          kdown = false;
                          break;

                  case 39:
                         kdown = false;
                         break;
                         }       
                }); 
 
           function changePlayerAnimation( animationName, animNumber ){
 				   registerUserKeyPressed(); 
				    defaultAnimation.hide(); 
            currentAnimation = animationName; 
            currentAnimation.css("left", "" + xPos + "px");     
            currentAnimation.show(); 
            currentAnimation.setAnimation( animNumber, waitAnimation()); 
				    registerUserAttackCount();
				}
 
                function waitAnimation(){
                }

                function stopCurrentAnimation() {
                      kdown = false;
                      var sprite = currentAnimation;  
                      stopAnimation( sprite ); 
                } 
   
                 function registerUserKeyPressed(){
				  if( isCollided ) kdown = true;
				      else kdown = false;
				 }

                 function whoWon(){
				    document.getElementById("log1").innerHTML = " abobo won .......";
                    aboboDefaultAnimation.hide();
                    aboboDefaultAnimation = $("#aboboWin");
					aboboDefaultAnimation.css("left", "" + aboboXPos + "px");
                    aboboDefaultAnimation.show();
			        isCollided = false;
					defaultAnimation.hide();
					defaultAnimation = $("#ryuRollForward");
					defaultAnimation.css("left", "" + xPos + "px");
					defaultAnimation.css("top", "" + 70 + "px");
                    defaultAnimation.show();
					defaultAnimation.setAnimation(3, gameOverAnimation());
                    aboboAttackCount = 0; 
					gameOver = true;
				 }
                 
				 //This method is used to chase the player when a fight begins 
                 function chasePlayer(){
				 }

                function stopAnimation( sprite ){
                   if( !kdown ) {
                   res = window.setTimeout(function() {
                        sprite.hide();
                        defaultAnimation.show();   
                        clearTimeout( res ); 
                   }, 200);
                  }     
                }

                function moveRight() {
                   xPos = xPos + xdelta;  
                   defaultAnimation.css("left", "" + xPos + "px");
                }

                function moveLeft() {
                   xPos = xPos - 15;  
				   if( xPos <= 0 ) xPos = 0;
				   defaultAnimation.css("left", "" + xPos + "px");
                   if( !detectCollision() ) {
                      userAttackCount = 0;
                      isCollided = false;  
                    }
                }   
                
                function moveAboboRight( abobo ) {
                  aboboXPos =  aboboXPos + 15;
                  abobo.css("left", "" + aboboXPos + "px");
                }

                function moveAboboLeft( abobo ) {
                  aboboXPos =  aboboXPos - 10;
                  abobo.css("left", "" + aboboXPos + "px");
                } 

                function detectCollision() {
                   var left = defaultAnimation.position().left;
                   if( left >= aboboXPos - DISTANCE ) return true; 
                   else return false;                       
                }

                function setCollided() {
                   isCollided = true;
                }

                function registerUserAttackCount() {
                   if( isCollided ) userAttackCount++;
                   else userAttackCount = 0;                      
                } 

                function getMoves(moves){
                  return moves[Math.round(Math.random()*(moves.length - 1))];
				}

                function log( msg ) {
                   document.getElementById("log").innerHTML = "";
                   document.getElementById("log").innerHTML = msg;  
                }   
                 $().setLoadBar("loadingBar", 600);
                 $.playground().startGame();
              });
        </script>
    </head>
    <body>
        <h2 id="message"></h2>
        <div id = "log">value:</div>
		<div id = "log1">value1:</div> 
        <div id ="playground" style="width: 350px; height: 50px; background: white"></div>
    </body>
</html>



